package com.api.mc
{
	import com.game.btnClass.BtnClass_goto;
	import com.game.display.AutoGCMovieClip;
	import com.game.utils.MyTimer;
	
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class FaceList extends BasicMc
	{
		private var _faceArray:Array = new Array();

		private var _sendFun:Function;
		private var _closeFun:Function;
		
		private var _waitTime:uint=1*1000;
		private var _myTimer:MyTimer=new MyTimer();
		
		private var _isGc:Boolean=false;
		private var _isInThis:Boolean=false;
		
		
		public function FaceList(sendFun:Function,closeFun:Function)
		{
			_faceArray.push([{fName:"yd.swf", desc:"晕倒"}, {fName:"tp.swf", desc:"调皮"}, {fName:"dx.swf", desc:"大笑"}, {fName:"hx.swf", desc:"害羞"}, {fName:"hs.swf", desc:"好色"}, {fName:"qw.swf", desc:"亲吻"}, {fName:"xd.swf", desc:"心动"}, {fName:"xs.swf", desc:"心碎"}, {fName:"lh.swf", desc:"流汗"}, {fName:"yh.swf", desc:"疑惑"}]);
			_faceArray.push([{fName:"dt.swf", desc:"点头"}, {fName:"yt.swf", desc:"摇头"}, {fName:"ot.swf", desc:"呕吐"}, {fName:"kb.swf", desc:"狂扁"}, {fName:"ll.swf", desc:"流泪"}, {fName:"fn.swf", desc:"愤怒"}, {fName:"ng.swf", desc:"难过"}, {fName:"zk.swf", desc:"抓狂"}]);
			_faceArray.push([{fName:"zy.swf", desc:"厉害"}, {fName:"bs.swf", desc:"鄙视"}, {fName:"ws.swf", desc:"握手"}, {fName:"gz.swf", desc:"鼓掌"}, {fName:"zt.swf", desc:"猪头"}]);
			
			_sendFun=sendFun;
			_closeFun=closeFun;
			init();
		}
		private function init():void{
			var _total:uint=0;
			for(var i:uint=0;i<_faceArray.length;i++){
				_total+=_faceArray[i].length
				for(var n:uint=0;n<_faceArray[i].length;n++){
					
					var _btn:FaceListBtn=new FaceListBtn(_faceArray[i][n]);
					_btn.x=5+27*n;
					_btn.y=5+22*i;
					addChild(_btn);
					addMouseEvent(new BtnClass_goto(_btn,faceClick,faceBtnOut,faceBtnOver,true));
				}
			}
			faceBtnOut();
			this.addEventListener(Event.ADDED_TO_STAGE,onStage);
			
		}
		private function onStage(e:Event):void{
			this.stage.addEventListener(MouseEvent.MOUSE_DOWN,thisMouseDown);
			this.removeEventListener(Event.ADDED_TO_STAGE,onStage);
		}
		private function thisMouseDown(e:MouseEvent):void{
			if(e.target!=this&&!_isInThis){
				_closeFun();
			}
		}
		private function faceBtnOver():void{
			_myTimer.gc();
			_isInThis=true;
		}
		private function faceBtnOut():void{
			_isInThis=false;
			_myTimer.setTimer(_closeFun,_waitTime,1)
		}
		private function faceClick(e:MouseEvent):void{
			_sendFun((e.currentTarget as FaceListBtn).faceDataObj);
			_closeFun();
		}
		public function gc():void{
			if(_isGc){
				return;
			}
			_isGc=true;
			delMouseEvent();
			delThisAllDis();
			_myTimer.gc();
			_myTimer=null;
			_sendFun=null;
			_closeFun=null;
			_faceArray=null;
			this.stage.removeEventListener(MouseEvent.MOUSE_DOWN,thisMouseDown);
		}
	}
}